Repository navigation
fix(gix): rename empty files in native tree diffs like Git - #2358
Merged
Byron merged 1 commit intoNov 24, 2026
Merged
Conversation
<!-- agent: Claude --> On the Gix backend, `Diffable.diff()` between two trees or commits builds its result in `_backend.tree_diff()`. When the added and deleted blob IDs pair up unambiguously, the adapter asks Gix for exact rename tracking with `gix.Rewrites(percentage=None)`. GixPython's `Rewrites` defaults to `track_empty=False`, the merge-style setting that never pairs empty blobs, while `git diff -M` (and the CLI backend) defaults to `--rename-empty` and reports an empty file moved from `a` to `b` as `R100`. So for a commit that only renames an empty file (an `__init__.py`, a `.gitkeep`, a placeholder), the CLI backend returned one `R` diff with `renamed_file` set, and the Gix backend returned an `A` diff for the new path and a `D` diff for the old one. The same happened with `R=True`. Code that follows renames through `rename_from`/`rename_to`, or that treats additions and deletions differently from renames, saw a different history depending on the backend. The adapter now passes `track_empty=True`, which is the Gix mode that matches Git's default for this diff. No pairing is done in Python; the existing ambiguity guard still sends duplicate blob IDs to Git, so several empty files added or deleted at once keep using the CLI path. This is adapter configuration rather than a Gix bug, so no new ledger entry is added. Validation on Windows with CPython 3.11, Git 2.56.0 and GixPython 0.3.0 built from source: - `test_rename_of_empty_file`, using the new `diff.sh empty-rename` fixture, fails on the Gix backend before the change (two diffs instead of one) and passes on both backends after it. - A sweep of 18 tree pairs compared against the CLI backend (empty and non-empty renames, mode changes, symlink/file and gitlink cases, swaps, directory moves, both directions with `R=True`) differed only in the empty-rename case before the change and matches in every case after it; all pairs without duplicate blob IDs stayed native. - `test/test_diff.py` passes on the CLI backend (50 passed). On the Gix backend, `test_diff.py`, `test_gix_backend.py`, `test_cli_process_counts.py` and `test_commit.py` give 193 passed and 2 failed; the two failures (`test_native_repository_lifetime_and_refresh[sha1|sha256]`) fail identically without this change because the test machine has no global Git identity for its `git commit`. - `ruff check`, `ruff format --check`, `shellcheck`, `mypy` and `git diff --check` pass. The full suite was not run. Agent-Model: claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Gix aur Git backends mein empty file ko rename karne par different results mil rahe the. Git backend mein
git diff-tree -r -M --rawrename koR100ke roop mein report karta tha, jabki Gix backend katree_diff()usi change koA(add) aurD(delete) ke roop mein report kar raha tha.Iska reason the ki Gix ke
Rewritesmein defaulttrack_empty=Falsehota hai, jo merge-style behavior use karta hai. Jabki Git meingit diff -Mka default behavior--rename-emptyhota hai.Fix: Gix ke
Rewrites(percentage=None)meintrack_empty=Truepass kiya gaya hai, jisse empty file renames bhi Git ke behavior ke according detect hote hain. Python side par koi additional pairing logic add nahi ki gayi hai, aur duplicate blob IDs ab bhi existing ambiguity guard ke through handle hote hain.Is change ke liye
diff.sh empty-renamefixture add kiya gaya hai. Nayatest_rename_of_empty_filetest change se pehle Gix backend par fail hota tha, lekin change ke baad dono backends par successfully pass hota hai, includingR=Trueconfiguration ke saath.CLI backend ke against 18 tree pairs par testing ki gayi, jisme empty aur non-empty file renames, mode changes, symlink/file changes, gitlinks, swaps aur directory moves shamil the. Change se pehle sirf empty file rename wale case mein difference mila, jabki change ke baad sabhi cases mein dono backends ke results match hue.
Testing:
test_diff.pyCLI backend par successfully pass hota hai. Gix backend par sirftest_native_repository_lifetime_and_refreshke dono cases fail hote hain, jo is change ke bina bhi missing global Git identity ki wajah se same tarah fail hote hain.Iske alawa ruff, shellcheck, mypy aur
git diff --checksuccessfully pass hote hain.